package bb.lanxing.lib.devices.ble.device;

import android.content.Context;

import java.io.File;

import bb.lanxing.lib.devices.api.SmartDevice;
import bb.lanxing.lib.devices.ble.XOSSSGFileHelper;
import bb.lanxing.lib.devices.core.exception.AbortedException;
import bb.lanxing.lib.devices.core.exception.TimeoutException;
import bb.lanxing.lib.devices.sprint.Command;
import bb.lanxing.lib.devices.sprint.Commands;
import bb.lanxing.lib.devices.sprint.XossDevice;
import android.util.Log;
import kotlin.NoWhenBranchMatchedException;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;

public class XossSGDevice extends XossDevice {
    public XossSGDevice(Context context, SmartDevice localDevice) {
        this(context, localDevice, null, 4, null);
    }

    @Override
    protected boolean _checkDeviceStatusAfterSend() {
        return true;
    }

    @Override
    public boolean shouldAutoConnection() {
        return true;
    }

    public XossSGDevice(Context context, SmartDevice smartDevice, String str, int i, DefaultConstructorMarker defaultConstructorMarker) {
        this(context, smartDevice, (i & 4) != 0 ? null : str);
    }

    public XossSGDevice(Context context, SmartDevice localDevice, String str) {
        super(context, localDevice, str);
    }

    @Override
    public void getFileList() {
        getFile(XOSSSGFileHelper.FILE.WORKOUT.getFileName());
    }

    @Override
    public void onServicesDiscovered() {
        super.onServicesDiscovered();
    }

    @Override
    public void handleExceptionForSender(Command command, Throwable th) {
        if ((th instanceof TimeoutException) || (th instanceof AbortedException)) {
            sendCmd(Commands.create(31, null));
        }
        super.handleExceptionForSender(command, th);
    }

    @Override
    public void _sendFile(File file) {
        ensureIdleStatus();
        super._sendFile(file);
    }

    @Override
    public void _getFile(String str) {
        ensureIdleStatus();
        super._getFile(str);
    }

    @Override
    public void _delete(String str) {
        ensureIdleStatus();
        super._delete(str);
    }

    @Override
    protected File transferReceivedFileByName(String fileName) {
        XOSSSGFileHelper xOSSSGFileHelper = XOSSSGFileHelper.INSTANCE;
        String model = getModel();
        String serial = getSerial();
        String sandBoxWorkRootDir = xOSSSGFileHelper.getSandBoxWorkRootDir(model, serial);
        XOSSSGFileHelper.FILETYPE from = XOSSSGFileHelper.FILETYPE.companion.from(fileName);
        Log.d("wangsm_bt", " XossSGDevice,   transferReceivedFileByName:  " + fileName);
        if (from != null) {
            int index = from.ordinal() + 1;
            switch (index) {
                case 1:
                    return new File(XOSSSGFileHelper.INSTANCE.getFileFolderPath(sandBoxWorkRootDir, XOSSSGFileHelper.FILE.WORKOUT_TXT), fileName);
                case 2:
                    return new File(XOSSSGFileHelper.INSTANCE.getFileFolderPath(sandBoxWorkRootDir, XOSSSGFileHelper.FILE.WORKOUT), fileName);
                case 3:
                    XOSSSGFileHelper.FILE from2 = XOSSSGFileHelper.FILE.Companion.from(fileName);
                    if (from2 != null) {
                        return new File(XOSSSGFileHelper.INSTANCE.getFileFolderPath(sandBoxWorkRootDir, from2), fileName);
                    }
                    return null;
                case 4:
                    return new File(XOSSSGFileHelper.INSTANCE.getFileFolderPath(sandBoxWorkRootDir, XOSSSGFileHelper.FILE.MAPS), fileName);
                case 5:
                    return new File(XOSSSGFileHelper.INSTANCE.getFileFolderPath(sandBoxWorkRootDir, XOSSSGFileHelper.FILE.ROUTE_BOOKS), fileName);
                case 6:
                    return new File(XOSSSGFileHelper.INSTANCE.getFileFolderPath(sandBoxWorkRootDir, XOSSSGFileHelper.FILE.GNSS), fileName);
                case 7:
                    return new File(XOSSSGFileHelper.INSTANCE.getFileFolderPath(sandBoxWorkRootDir, XOSSSGFileHelper.FILE.LOG), fileName);
                default:
                    throw new NoWhenBranchMatchedException();
            }
        }
        return null;
    }

    @Override
    protected boolean isSendDynamicSizeYModems(File file) {
        return file.length() > 200;
    }
}
